<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>List of Dict</title>
<!-- base lib -->
<script type="text/javascript" src="../../../script/jquery.js"></script>
<script type="text/javascript" src="../../../script/util.js"></script>

<!-- third party lib -->
<link rel="stylesheet" type="text/css" href="../../../plugin/flexigrid/css/flexigrid/flexigrid.css">
<script type="text/javascript" src="../../../plugin/flexigrid/flexigrid.js"></script>

<link rel="stylesheet" href="../../../plugin/jquery_ui/css/jquery-ui.css">

<script src="../../../plugin/jquery_ui/jquery.ui.core.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.widget.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.button.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.mouse.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.draggable.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.position.js"></script>
<script src="../../../plugin/jquery_ui/jquery.ui.resizable.js"></script>

<script src="../../../plugin/jquery_ui/jquery.ui.dialog.js"></script>


<!-- my lib -->
<style>
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
}
        
.flexigrid div.fbutton .add {
  background: url(../../../plugin/flexigrid/css/images/add.png) no-repeat center left;
}   

.flexigrid div.fbutton .delete {
  background: url(../../../plugin/flexigrid/css/images/close.png) no-repeat center left;
}   

.flexigrid div.fbutton .edit {
  background: url(../../../plugin/flexigrid/css/images/modify.png) no-repeat center left;
}   

        
</style>

<script type="text/javascript">
var dataGrid = null ;

window.onload=function (){
	dataGrid = $("#dataGrid").flexigrid(
        {
            url: '/easyframe/system/dict_list.action',
            dataType: 'xml',
            colModel : [
                {display: '<input type="checkbox" name="checkAll" onclick="checkIds(this)" />', name:"dict_id", width:30, sortable: false, formater:idsCheckboxes},
                {display: 'Code', name : 'code_', width : 40, sortable : true, align: 'center'},
                {display: 'Domain', name : 'domain_', width : 120, sortable : true, align: 'left'},
                {display: 'Name', name : 'name_', width : 180, sortable : true, align: 'left'},
                {display: 'id_', name : 'dict_id', width : 130, hide: true}
                ],/*
            searchitems : [
                {display: 'ISO', name : 'iso'},
                {display: 'Name', name : 'name_', isdefault: true}
                ],*/
            buttons : [
                {name :'添加',bclass:'add',onpress:toAdd},
                {name :'修改',bclass:'edit',onpress:toEdit},
                {name :'删除',bclass:'delete',onpress:doDelete},
                {name :'选取',bclass:'search',onpress:doSelect},
                {separator : true}
                ],
            sortname: "name_",
            sortorder: "asc",
            usepager: true,
            title: '这个是我的测试表格',
            useRp: true,
            rp: 15,
            showTableToggleBtn: false,
            width: 880,
            //onSubmit: doList,
            height: 400,
            searchDivName: "searchFormDiv",
            searchFormName:"searchForm",
            rowIdName:"dict_id"
	    }
	);

	/*  
	$('#sform').submit
	(
	    function ()
	        {
	            $('#dataGrid').flexOptions({newp: 1}).flexReload();
	            return false;
	        }
	);                      
	*/

    doList();

    //alert(getWindowParams("dictList")) ;
}

function doList() {
	
    //$("#dataGrid").flexOptions({params: $(searchForm).serializeArray()}).flexReload();
    dataGrid.flexReload() ;
    return true;
}

var windowParams = getWindowParams(window.name) ;

function doSelect() {
    var ids = dataGrid.getSelectedIds() ;


    windowParams.onReturn(ids[0]) ;
    
    windowParams.windowMe.dialog("close");

    window.href = "" ;
}

function toAdd2() {
    //editForm.action = "/easyframe/system/dict_create.action" ;
    
    $('<div style="width:100%;heigth:100%;">sss</div>').dialog({
        closed:false,
        height: 500,
        width:600,
        modal:true,
        buttons: { "Ok": function() { $.post(editForm.action, $(editForm).serialize(), doAddOnRetrun); } }
    });
}

var windowMe = null ;
function toAdd() {
    var params = {} ;
    windowMe = openWindow("dictEdit", "Edit Dict", "/easyframe/html/system/dict/edit.html" , params, {"OK":doAdd}, 500, 600) ;
}

function doAdd() {
    top.$.post("/easyframe/system/dict_create.action", top.$(top.dictEdit.document.editForm).serialize(), doAddOnRetrun); 
}

function doAddOnRetrun(xml) {

    doList();
    
    windowMe.dialog("close");
}

function toEdit() {
    var ids = dataGrid.getSelectedIds() ;
	
    if(ids.length==1){
    	//alert(dataGrid.getSelectedRows()[0]);
    	dataGrid.fillEditForm(editForm) ;
        editForm.action = "/easyframe/system/dict_update.action" ;
        
        $('#dialogEdit').dialog({
            closed:false,
            height: 500,
            modal:true,
            buttons: { "Ok": function() { $.post(editForm.action, $(editForm).serialize(), doEditOnRetrun); } }
        });
    }else if(ids.length>1){
        alert("请选择一个修改,不能同时修改多个记录!");
    }else if(ids.length==0){
        alert("请选择一个您要修改的记录!")
    }
}

function doEditOnRetrun(xml) {
    doList();
    
    $('#dialogEdit').dialog("close");
}

function doDelete() {
    editForm.action = "/easyframe/system/dict_delete.action" ;
    
    if (confirm("确定要删除数据吗？")) {
        $.post(editForm.action, $(searchForm).serialize(), doDeleteOnRetrun); 
    }

}

function doDeleteOnRetrun(xml) {
    doList();
}

function idsCheckboxes(value) {
	return "<input type='checkbox' value='" + value + "' name='ids' />" ;
}

function checkIds(checkboxAll) {
	var ids = document.all("ids") ;

	for (var i = 0 ; i < ids.length ; i ++) {
		ids[i].checked = checkboxAll.checked ;
	}
}
</script>
</head>
<body topmargin="0" leftmargin="0">
  <form action="/easyframe/system/dict_list.action" method="post" name="searchForm" id="searchForm"  topmargin="0" leftmargin="0" >
    <input type="hidden" name="pageSize"/>
    
	<table id="dataGrid" style="display:none">
	</table>
	<div style="display: none">
	<div id="searchFormDiv">
          <table width="100%" style="margin-top: 4px">
              <tr valign="middle">
                 <td>domain:<input type="text" name="dict.domain_"/></td>
                 <td>code:<input type="text" name="dict.code_"/></td>
                 <td>name:<input type="text" name="dict.name_"/></td>
               </tr>
          </table>
	</div>
	</div>
  </form>

  <!--             
	<div id="dialogEdit" title="添加" style="display: none">
	  <form action="" method="post" name="editForm" id="editForm">
	      <input type="hidden" name="dict.dict_id"/>
	      <table>
              <tr><td>domain_:</td></tr>
              <tr><td><input type="text" name="dict.domain_"/><input type="button" value="getDict" onclick="getDict()" /></td></tr>
              <tr><td>code:</td></tr>
              <tr><td><input type="text" name="dict.code_"/></td></tr>
              <tr><td>name:</td></tr>
              <tr><td><input type="text" name="dict.name_"/></td></tr>
	      </table>
	  </form>
	</div>
   -->
</body>
</html>